package response

import (
	"gitee.com/zhanglibin/gmall/utils/consts"
	"github.com/gin-gonic/gin"
	"net/http"
)

func ReturnJson(Context *gin.Context, httpCode int, dataCode int, msg string, data interface{}) {
	if data == nil {
		data = struct{}{}
	}

	//Context.Header("key2020","value2020")  	//可以根据实际情况在头部添加额外的其他信息
	Context.JSON(httpCode, gin.H{
		"errcode": dataCode,
		"errmsg":  msg,
		"data":    data,
	})
}

// 成功
func Success(c *gin.Context, data interface{}) {
	ReturnJson(c, http.StatusOK, consts.CurdStatusOkCode, consts.CurdStatusOkMsg, data)
}

// 失败
func Failure(c *gin.Context, dataCode int, msg string, data interface{}) {
	ReturnJson(c, http.StatusBadRequest, dataCode, msg, data)
}
